import {sql} from "../expressExt/db/Isql";
import {SqlBuilder} from "../expressExt/db/SqlBuilder";
import {Config} from "../configExt/Config";
import {mongo} from "../expressExt/mongo"
import {ObjectID} from "mongodb";
import {MongoBuilder} from "../expressExt/db/MongoBuilder";
import {array, arrayString} from "../expressExt/public/sdf";


/**
 * 数组成员类型
 */
class TestTableSub {
    a = ""

}

//表名，对应与数据库中的表名
class TestTable {
    /**
     * id字段
     */
    _id = new ObjectID()


    @sql.index()//普通索引
    age = 0;


    @sql.indexText()//全文索引
    name: string = "";

    //嵌套对象
    s = {a: 1, b: 2};

    //数组
    arr = array(TestTableSub)

    arr2 = arrayString()
}
export class db {


    /**
     *用于构造TestTable表的sql语句
     */
    static get TestTable() {
        return new MongoBuilder(TestTable, Config.mongo);
    }
}


async function test() {

    /**
     *
     */
    await db.TestTable
        .where(f => f.age.gt(0) | f.name.eq("") & (f.age.eq(2) | f.s.a.eq(2)))
        .updatePromise(f => f.arr.push({a: "aaa"}) & f.name.set("123") & f.age.inc(1) & f.arr2.pull(f => f.in(["0", "1"])))

    let res = await (await db.TestTable.where(f => f.s.a.eq(1)).collection()).findOneAndDelete({
        "aaa": 123,
        "bbb": {$gt: 0}
    });
}

let p = TestTableSub;
let a = TestTableSub.prototype;
function Sub() {

}
Sub.prototype = new TestTableSub();
Sub.prototype.ss = () => {

}
let dd = Sub;
let b = (TestTableSub as any).__proto__;
let c = new Sub();
test()


import {rpc} from "../rpc/rpc";
async function aa() {
    await rpc.mem().set("key", "val");
    let res = await rpc.mem().get("get");
    console.log(res);
    await rpc.mem().delete("key");
}